messages = [
            {'role': 'user', 
            'content': [{'text': '如果有文本回答，请使用中文', 
                        'type': 'text'}, 
                        {'image_url': {'url': 'http://huayiyi-ai.oss-cn-shanghai.aliyuncs.com/test_tmp/1762407601188-0275a518-f76d-4b9a-8891-5c5046a7695a.png'}, 
                        'type': 'image_url'}, 
                        {'text': '请把上面的衣服颜色变成红色', 'type': 'text'}
                        ]}, 
            ]

import requests
import time

port=20026

# 1. 发送消息到flask_nano，获得task_id
flask_url = f"http://127.0.0.1:{port}/chat"
data = {
    "messages": messages
}
resp = requests.post(flask_url, json=data)
if resp.status_code == 200:
    result = resp.json()
    print("提交任务返回：", result)
    if result.get("success") and "task_id" in result:
        task_id = result["task_id"]
        print("获得task_id:", task_id)

        # 2. 轮询查结果
        query_url = f"http://127.0.0.1:{port}/query_chat"
        poll_count = 0
        while True:
            poll_count += 1
            query_resp = requests.post(query_url, json={"task_id": task_id})
            query_data = query_resp.json()
            print(f"[轮询第{poll_count}次] 状态: {query_data.get('status')}")
            if query_data.get("status") == "completed":
                print("查询结果:", query_data.get("result"))
                break
            # elif query_data.get("status") == "failed":
            #     print("任务失败")
            #     break
            # elif query_data.get("status") == "not_found":
            #     print("未找到任务")
            #     break
            else:
                time.sleep(1)
    else:
        print("提交任务失败:", result)
else:
    print("请求失败:", resp.status_code, resp.text)
